package com.hand.llq25404.controller;

import com.hand.llq25404.service.impl.ExcleImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;

@Controller
public class ExcelController {

	@Autowired
	ExcleImpl excleImpl;

	@RequestMapping("/dateTable")
	public String down(HttpServletResponse response, @RequestParam("name") String name) {
		response.setContentType("application/binary;charset=UTF-8");
		try {
			ServletOutputStream out = response.getOutputStream();
			//设置文件头：最后一个参数是设置下载文件名(这里我们叫:工资表.xls)
			response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(name + ".xls", "UTF-8"));

			String[] titles = {"物料编码", "物料描述", "物料单位", "生效时间从", "生效时间至", "是否启用"};
			excleImpl.export(titles, out);
			return "";
		} catch (Exception e) {
			e.printStackTrace();
			return "导出信息失败";
		}
	}

}